package com.example.controller;

import com.example.config.Utils;
import com.example.entity.Clients;
import com.example.service.ClientsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/clientss")
@CrossOrigin(origins = "*")
public class ClientsController {
    @Autowired
    private ClientsService clientsService;

    @GetMapping("/all")
    public List<Clients> getAllClientss() {
        return clientsService.getAllClientss();
    }
    @GetMapping("/list")
    public List<Clients> listClientss(@RequestParam Map<String, Object> params) {
        System.out.println("listClientss by params==="+ params);
        return clientsService.listClientssByParams(params);
    }

    @PostMapping("/add")
    public Clients addClients(@RequestBody  Clients clients) throws Exception {
        System.out.println("addClients===");
        Utils.printValues(clients);
        clientsService.addClients(clients);
        return clients;
    }

    @DeleteMapping("/delete/{id}")
    public String deleteClients(@PathVariable Integer id) {
        System.out.println("deleteClients by id==="+ id);
        clientsService.deleteClients(id);
        return "success";
    }

    @PostMapping("/deleteByIds")
    public String deleteClientssByIds(@RequestBody List<String> ids) {
        System.out.println("deleteClientss by ids==="+ ids);
        clientsService.deleteClientss(ids);
        return "success";
    }

    @PostMapping("/update")
    public String updateClients(@RequestBody Clients clients) throws Exception {
        Utils.printValues(clients);
        clientsService.updateClients(clients);
        return "success";
    }


}